package service

import (
	"time"

	"github.com/go-kit/log"
)

type LoggingMiddleware struct {
	Logger log.Logger
	Next   IServer
}

func (mw LoggingMiddleware) Hello(name string) (s string) {
	defer func(begin time.Time) {
		mw.Logger.Log(
			"method", "Hello",
			"name", name,
			"s", s,
			"took", time.Since(begin),
		)
	}(time.Now())
	return mw.Next.Hello(name)
}

func (mw LoggingMiddleware) Bye(name string) (s string) {
	defer func(begin time.Time) {
		mw.Logger.Log(
			"method", "Bye",
			"name", name,
			"s", s,
			"took", time.Since(begin),
		)
	}(time.Now())
	return mw.Next.Bye(name)
}
